package com.module.realm;

import com.module.realm.CustomRealm;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.Subject;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

/**
 * 匿名登录的资源
 */

public class CryptonymRealm extends CustomRealm {
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        String name = (String) principalCollection.getPrimaryPrincipal();
        //添加匿名用户的访问资源
        List<String> permissions=new ArrayList<>();
        permissions.add("/cryptonym");
        permissions.add("/dolook");
        permissions.add("/dosomting");
        SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();
        for (String per:permissions
        ) {
            simpleAuthorizationInfo.addStringPermission(per);
        }
        return simpleAuthorizationInfo;
    }
}
